// Decompiled by Jad v1.5.7f. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   DataModelInterface.java

package com.iphaeton.lms.course.scorm12.datamodel;

import com.iphaeton.lms.course.scorm12.DebugIndicator;
import com.iphaeton.lms.course.scorm12.datamodel.cmi.CMIRequest;
import com.iphaeton.lms.course.scorm12.datamodel.cmi.DMErrorManager;
import java.io.PrintStream;
import java.util.StringTokenizer;

// Referenced classes of package com.iphaeton.lms.course.scorm12.datamodel:
//            SCODataManager

public class DataModelInterface
{

    public DataModelInterface()
    {
    }

    public String processGet(String theRequest, SCODataManager scoData, DMErrorManager dmErrMgr)
    {
        if(_Debug)
        {
            System.out.println("");
            System.out.println("**********************************");
            System.out.println("In DataModelInterface::processGet()");
            System.out.println("**********************************");
            System.out.println("");
        }
        String result = new String("");
        if(_Debug)
            System.out.println("In DataModelInterface::processGet");
        if(isValidRequest(theRequest))
        {
            CMIRequest request = new CMIRequest(theRequest, true);
            result = scoData.getValue(request, dmErrMgr);
        } else
        {
            if(_Debug)
                System.out.println("Data model not supported by SCORM");
            dmErrMgr.SetCurrentErrorCode("201");
        }
        if(_Debug)
        {
            System.out.println("");
            System.out.println("**********************************");
            System.out.println("Returning to API: [" + result + "]");
            System.out.println("**********************************");
            System.out.println("");
        }
        return result;
    }

    public void processSet(String theRequest, SCODataManager scoData, DMErrorManager dmErrMgr)
    {
        if(_Debug)
        {
            System.out.println("");
            System.out.println("***********************************");
            System.out.println("In DataModelInterface::processSet()");
            System.out.println("***********************************");
            System.out.println("");
        }
        StringTokenizer stk = new StringTokenizer(theRequest, ",", false);
        String tmpRequest = stk.nextToken();
        if(isValidRequest(tmpRequest))
        {
            CMIRequest request = new CMIRequest(theRequest, false);
            scoData.setValue(request, dmErrMgr);
        } else
        {
            if(_Debug)
                System.out.println("Data model not supported by SCORM");
            dmErrMgr.SetCurrentErrorCode("201");
        }
    }

    private boolean isValidRequest(String theRequest)
    {
        boolean rtrnFlag = true;
        StringTokenizer stk = new StringTokenizer(theRequest, ".", false);
        int totalNumOfTok = stk.countTokens();
        if(totalNumOfTok < 2)
            rtrnFlag = false;
        String token = stk.nextToken();
        if(token.equals("cmi"))
            rtrnFlag = true;
        else
            rtrnFlag = false;
        return rtrnFlag;
    }

    private static boolean _Debug;

    static 
    {
        _Debug = DebugIndicator.ON;
    }
}
